<?php
namespace Mp\Service\Widget;
use Illuminate\Contracts\Support\Renderable;
use Mp\Service\Widget\Input;

class Checkbox extends Input {

	protected $label = 'checkbox';

	protected $theme = "border";  //border fadein default

	protected $style = 'info'; //

	protected $enable = true;

	protected $module = 'border';

	protected $source = [];  //数据源

	protected $checks = [];

	protected $data;


	protected $view = 'Mp::widgets.checkbox';



	protected function _init($params = []){
		$this->label = $params['label'] ?? $this->label;
		$this->size = $params['size'] ?? $this->size;
		$this->type = $params['class'] ?? $this->class;
		
		$this->source = $params['source'] ?? $this->source;
		
		$this->data =  [
			'name' =>$this->name,
			'value' => array($this->value),
			'label' => $this->label,
			'size' => $this->size,
			'class' => $this->class,
			'source' => $this->source,
			'enable' =>$this->enable,
			'module' => $this->module,
			'style' => $this->style,
		];
	} 

	public function checkbox($params = []){
		$checkbox = [
			'value' => $params['value'],
			'checked' => false,
			'label' => $params['label'] ?? 'checkbox',
		];
		

		array_push($this->source , $checkbox);
		$this->data['source'] = $this->source;
		return $this;
	}

	public function checks($params = []){
		foreach($this->data['source'] as &$val){
			if(in_array($val['value'],$params)){
				$val['checked'] = true;
			}
		}
		return $this;
	}

	public function render(){
		$this->checks();
		return parent::render();
	}



	
}